package com.warmheart.core.co.base;

import com.warmheart.core.co.builder.CoBuilder;
import com.warmheart.core.co.oper.Co;
import com.warmheart.core.cors.builder.CoRsBuilder;
import com.warmheart.core.cors.enums.DateFormatEnum;

/**
 * 
 * @ClassName: BaseCoBuilder
 * @Description: 自定义查询、排序基本实现类
 * @author ZhangJianyang
 * @date 2025-06-16 09:37:02
 *
 * @param <T>
 */
public abstract class BaseCoBuilder<T extends CoRsBuilder<?, ?>, E extends CoBuilder<T>> implements CoBuilder<T> {

    protected abstract E self();

    private Co<T, E> id;

    private Co<T, E> createDate;

    private Co<T, E> createBy;

    private Co<T, E> updateDate;

    private Co<T, E> updateBy;

    private Co<T, E> remarks;

    private Co<T, E> delFlag;

    public Co<T, E> id() {
        if (this.id == null) {
            this.id = new Co<T, E>(self(), "id");
        }
        return this.id;
    }

    public Co<T, E> createDate(DateFormatEnum... dateFormatEnums) {
        if (this.createDate == null) {
            if (dateFormatEnums != null && dateFormatEnums.length > 0) {
                this.createDate = new Co<T, E>(self(), "create_date", dateFormatEnums[0].getValue());
            } else {
                this.createDate = new Co<T, E>(self(), "create_date", DateFormatEnum.yyyy_MM_dd.getValue());
            }
        }
        return this.createDate;
    }

    public Co<T, E> createBy() {
        if (this.createBy == null) {
            this.createBy = new Co<T, E>(self(), "create_by");
        }
        return this.createBy;
    }

    public Co<T, E> updateDate(DateFormatEnum... dateFormatEnums) {
        if (this.updateDate == null) {
            if (dateFormatEnums != null && dateFormatEnums.length > 0) {
                this.updateDate = new Co<T, E>(self(), "update_date", dateFormatEnums[0].getValue());
            } else {
                this.updateDate = new Co<T, E>(self(), "update_date", DateFormatEnum.yyyy_MM_dd.getValue());
            }
        }
        return this.updateDate;
    }

    public Co<T, E> updateBy() {
        if (this.updateBy == null) {
            this.updateBy = new Co<T, E>(self(), "update_by");
        }
        return this.updateBy;
    }

    public Co<T, E> remarks() {
        if (this.remarks == null) {
            this.remarks = new Co<T, E>(self(), "remarks");
        }
        return this.remarks;
    }

    public Co<T, E> delFlag() {
        if (this.delFlag == null) {
            this.delFlag = new Co<T, E>(self(), "del_flag");
        }
        return this.delFlag;
    }
}
